package com.kw.drug.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kw.drug.entity.Druginfo;
import com.kw.drug.entity.Owinfo;

import com.kw.drug.mapper.DruginfoMapper;
import com.kw.drug.service.DruginfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service

public class DruginfoServiceImpl implements DruginfoService {
    @Autowired
    DruginfoMapper druginfoMapper;

    @Override
    public List<Druginfo> queryDruginfoList() {
        QueryWrapper<Druginfo> wrapper = new QueryWrapper<>();
        List<Druginfo> list = druginfoMapper.selectList(wrapper);
        return list;
    }

    @Override
    public IPage<Druginfo> selectDruginfoPage(int pageNum, int pageSize, String param) {
        QueryWrapper<Druginfo> queryWrapper = new QueryWrapper<>();
        if (StringUtils.isNotEmpty(param)) {
            queryWrapper.like("name", param);
        }
        Page<Druginfo> page = new Page<>(pageNum, pageSize);
        return druginfoMapper.selectPage(page, queryWrapper);
    }

    @Override
    public Druginfo selectDrugById(Integer id) {
        Druginfo druginfo = druginfoMapper.selectById(id);
        return druginfo;
    }

    @Override
    public Integer updateDrugInfo(Druginfo druginfo) {
        int i = druginfoMapper.updateById(druginfo);
        return i;
    }

    @Override
    public Integer deleteById(Integer id) {
        int i = druginfoMapper.deleteById(id);
        return id;
    }

    @Override
    public Integer addDrugInfo(Druginfo druginfo) {
        int insert = druginfoMapper.insert(druginfo);
        return insert;
    }
}
